package com.suixinsanren.design.state.demo.demo06;

public class WinnerState implements State {

    private final GumballMachine gumballMachine;

    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("欧皇，请先不要投币，我们正在为您准备糖果");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("欧皇，无法退还硬币，我们正在为您准备糖果");
    }

    @Override
    public void turnCrank() {
        System.out.println("欧皇，现在无法开始游戏，我们正在为您准备糖果");
    }

    @Override
    public void dispense() {
        gumballMachine.releaseGumball();
        if (gumballMachine.getCount() > 0) {
            gumballMachine.releaseGumball();
            if (gumballMachine.getCount() > 0) {
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            } else {
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        } else {
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }
    }

    @Override
    public String toString() {
        return "欧皇，正在准备糖果";
    }
}
